/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.edu.ntu.yyl.service.imlp;

import cn.edu.ntu.yyl.dao.ArticleDao;
import cn.edu.ntu.yyl.dao.UserInfoDao;
import cn.edu.ntu.yyl.pojo.article.Article;
import cn.edu.ntu.yyl.pojo.article.ArticleComment;
import cn.edu.ntu.yyl.vo.CommentVO;
import cn.edu.ntu.yyl.pojo.user.UserInfo;
import cn.edu.ntu.yyl.service.CommentVOService;
import cn.edu.ntu.yyl.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CommentVOServiceImpl implements CommentVOService {
    @Autowired
    private ArticleDao articleDao;
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private CommentService commentService;
    private CommentVO commentShowmment = new CommentVO();
    @Override
    public List<CommentVO> Show(List<ArticleComment> articleCommentList) {
        List<CommentVO> commentVOList = new ArrayList<>();
        for (ArticleComment articleComment:articleCommentList) {
            commentVOList.add(Show(articleComment));
        }
        return commentVOList;
    }

    @Override
    public CommentVO Show(ArticleComment articleComment) {
        UserInfo userInfo = userInfoDao.SelectByComment(articleComment);
        Article article = articleDao.SelectArticleByComment(articleComment);
        List<ArticleComment> ChildrenList = commentService.SelectChildrenCommentByComment(articleComment);
        ArticleComment parent = commentService.SelectFatherCommentByComment(articleComment);
        commentShowmment.setArticleComment(articleComment);
        commentShowmment.setUserInfo(userInfo);
        commentShowmment.setArticle(article);
        commentShowmment.setParent(parent);
        commentShowmment.setChildrenList(ChildrenList);
        return commentShowmment;
    }
}
